<?php
namespace api\controllers;

use Yii;
use yii\web\Controller;

/**
 * Site controller
 */
class SiteController extends Controller
{
    /**
     * Displays homepage.
     *
     * @return string
     */
    public function actionIndex()
    {
        try {
            define('API_HOST', Yii::$app->request->hostName);

            $projectRoot = Yii::getAlias('@api');

            $json_file = $projectRoot . '/swagger-ui/iceke-swagger.json';

            $swagger = \Swagger\scan([
                $projectRoot.'/modules/'
            ], [
            ]);

            $is_write = file_put_contents($json_file, $swagger);
            if ($is_write == true) {
                echo 'make ok<br>';
            } else {
                echo 'make fail<br>';
            }
            echo '<a href="http://apidoc.iceke.com">http://apidoc.iceke.com</a>';
        } catch (\Exception $e) {
            // var_dump($e->getMessage());
            throw $e;
        }
    }

}
